<!DOCTYPE html>
<html>
<head>
<title>SMART - Dashboard</title>
<jsp:include page="../include/head.jsp" />
</head>
<body>
   <div class="wrapper">
      <!-- 导航区 -->
      <jsp:include page="../include/topnav.jsp" />
      <!-- 左侧菜单区 -->
      <jsp:include page="../include/menu.jsp" />
      <!-- 右侧边栏 -->
      <jsp:include page="../include/right.jsp" />
      <!-- Main section-->
      <section>
         <!-- Page content-->
         <div class="content-wrapper">
            <div class="content-heading">编辑资讯</div>
            <div class="panel panel-default">
            	<div class="panel-body">
            		<jsp:include page="../include/info.jsp" />
					<form role="form" action="admin/info/edit" method="post" class="form-horizontal">
						<c:if test="${obj ne null}">
						<input type="hidden" name="id" value="${obj.id}" />
						</c:if>
						<div class="form-group">
							<label for="title" class="col-sm-2 control-label">类别</label>
							<div class="col-sm-4">
								<smt:enumSelect type="com.smart.consts.InfoType" value="${selectedType}" />
								<span class="text-muted">必选</span>
							</div>
							<label for="title" class="col-sm-2 control-label">标题</label>
							<div class="col-sm-4">
								<input type="text" class="form-control" id="title" name="title" value="${obj.title}" />
								<span class="text-muted">必填, 最佳展示长度为15-25个中文字符</span>
							</div>
						</div>
						
						<div class="form-group">
							<label for="keywords" class="col-sm-2 control-label">SEO关键字</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="keywords" name="keywords" value="${obj.keywords}" />
								<span class="text-muted">选填, SEO专属关键字</span>
							</div>
						</div>
						
						<div class="form-group">
							<label for="description" class="col-sm-2 control-label">SEO描述</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="description" name="description" value="${obj.description}" />
								<span class="text-muted">选填, SEO专属描述</span>
							</div>
						</div>
						
						<div class="form-group">
							<label for="crtTimeStr2" class="col-sm-2 control-label">发布日期</label>
							<div class="col-sm-4">
								<input type="text" class="form-control date" id="crtTimeStr2" name="crtTimeStr2" data-date-format="yyyy-mm-dd" value="${obj.crtTimeStr2}" />
								<span class="text-muted">选填, 如果不填， 则默认为当前时间</span>
							</div>
							<label for="source" class="col-sm-2 control-label">来源</label>
							<div class="col-sm-4">
								<input class="form-control" id="source" name="source" value="${obj.source}" />
								<span class="text-muted">选填, 消息来源</span>
							</div>
						</div>
						
						<div id="t2" style="">
							<div class="form-group">
								<label for="videoUrl" class="col-sm-2 control-label">视频URL</label>
								<div class="col-sm-10">
									<div class="input-group">
										<input type="text" class="form-control" id="videoUrl" name="videoUrl" value="${obj.videoUrl}" />
										<span class="input-group-btn">
											<button class="btn btn-default" id="btnViewVideoFile" type="button">浏览</button>
										</span>
									</div>
									<span class="text-muted">既可填写外部视频URL, 也可浏览(或上传)选择本服务器上的视频</span>
								</div>
							</div>
						</div>
						<div class="form-group">
							<label for="titleImage" class="col-sm-2 control-label">标题图片</label>
							<div class="col-sm-4">
								<div class="input-group">
									<input type="text" class="form-control" id="titleImage" name="titleImage" value="${obj.titleImage}" />
									<span class="input-group-btn">
										<button class="btn btn-default" id="btnViewTitleImage" type="button">浏览</button>
									</span>
								</div>
								<span class="text-muted">必填, 最佳宽高比400px X 200px</span><br />
							</div>
							<label for="bannerImage" class="col-sm-2 control-label">Banner大图</label>
							<div class="col-sm-4">
								<div class="input-group">
									<input type="text" class="form-control" id="bannerImage" name="bannerImage" value="${obj.bannerImage}" />
									<span class="input-group-btn">
										<button class="btn btn-default" id="btnViewBannerImage" type="button">浏览</button>
									</span>
								</div>
								<span class="text-muted">宽度必须能够撑满横屏</span><br />
							</div>
						</div>
						<div class="form-group">
							<label for="abstraction" class="col-sm-2 control-label">摘要</label>
							<div class="col-sm-10">
								<textarea class="form-control" id="abstraction" name="abstraction" rows="2">${obj.abstraction}</textarea>
								<span class="text-muted">选填, 最佳展示长度为50-75个中文字符</span>
							</div>
						</div>
						<div class="form-group">
							<div class="col-sm-2"></div>
							<div class="col-sm-10">
								<button type="submit" class="btn btn-primary">提交</button>  
								<a href="admin/info/list" class="btn btn-primary">返回到列表页</a>
								<a href="admin/info/edit" class="btn btn-primary">创建新资讯</a>
							</div>
						</div>
						<div class="form-group">
							<label for="content" class="col-sm-2 control-label">内容</label>
							<div class="col-sm-10">
								<textarea class="" id="content" name="content" rows="15">${obj.content}</textarea>
							</div>
						</div>
						<div class="form-group">
							<div class="col-sm-2"></div>
							<div class="col-sm-10">
								<button type="submit" class="btn btn-primary">提交</button>  
								<a href="admin/info/list" class="btn btn-primary">返回到列表页</a>
								<a href="admin/info/edit" class="btn btn-primary">创建新资讯</a>
							</div>
						</div>
					</form>
			 	</div>
			</div>
         </div>
      </section>
      <jsp:include page="../include/footer.jsp" />
   </div>
   <jsp:include page="../include/script.jsp" />
   <script src="ckfinder/ckfinder.js"></script>
   <script src="ckeditor/ckeditor.js"></script>
</body>
</html>
<script>
$('#mainMenu li').removeClass('active');
$('#menuInfo').addClass('active');

CKEDITOR.replace('content', {
	height: 800
});

/*
$('#infoTypeSelect').change(function(){
	//alert($(this).val());
	if($(this).val()=='7271634933534114615') {
		$('#t1').hide();
		$('#t2').show();
	}
	else {
		$('#t2').hide();
		$('#t1').show();
	}
});
*/
$('#btnViewBannerImage').click(function(){
	var that = $('#bannerImage');
	var finder = new CKFinder();
	finder.selectActionFunction = function(path){
		$(that).val(path);
		//$('#imagePreview').attr('src', path).css('width', '100%').css('height', 'auto').show();
	};
	finder.popup();
});

$('#btnViewVideoFile').click(function(){
	var that = $('#videoFile');
	var finder = new CKFinder();
	finder.selectActionFunction = function(path){
		$(that).val(path);
	};
	finder.popup();
});



$('#btnViewTitleImage').click(function(){
	var that = $('#titleImage');
	var finder = new CKFinder();
	finder.selectActionFunction = function(path){
		$(that).val(path);
		//$('#imagePreview').attr('src', path).css('width', '100%').css('height', 'auto').show();
	};
	finder.popup();
});

<c:if test="${obj ne null}">
$('#tags input').click(function() {
	var checked = $(this).is(':checked');
	var tagId = $(this).val();
	if(checked) {
		$.ajax({
			url: 'infoTag/add',
			data: {'infoId': '${obj.id}', 'tagId': tagId},
			success: function() {
				//alert('操作成功');
			},
			error: function() {
				alert('操作失败');
			}
		});
	}
	else {
		$.ajax({
			url: 'infoTag/delete',
			data: {'infoId': '${obj.id}', 'tagId': tagId},
			success: function() {
				//alert('操作成功');
			},
			error: function() {
				alert('操作失败');
			}
		});
	}
})
</c:if>
</script>